# -*- coding: utf-8 -*-
"""
Created on Thu Aug 25 12:21:02 2022

@author: xiong
"""
import redis
import logging
logger = logging.getLogger("facebook_spider")

class RedisConnector():
    error = ""
    def __init__(self,host,port,db):
        try:
            self.redis_conn=redis.ConnectionPool(host=host,port=port,db=db)
            self.cursor = redis.StrictRedis(connection_pool=self.redis_conn)
        except Exception as e:
            self.error = e
        
    def hget(self,path,key):
        return self.cursor.hget(path,key)
    
    def get(self,key):
        return self.cursor.get(key)
    
    def set_key_value(self,key,value):
        try:
            self.cursor.set(key,value)
            return "success"
        except Exception as e:
            return e
    def hdelete(self,path,key):
        try:
            self.redis_conn.hdel(path,key)
            return "deleted success"
        except:
            return "deleted fail"
